def bvAnalysis(dict, fvFn, noOfC, svFn, noOfR):
    bvList=[]
    fvDict={}
    svDict={}

    for k, v in dict.items():
        fvDict[k]=v[fvFn]
        svDict[k]=v[svFn]
    
    minFv=min(fvDict.values())
    maxFv=max(fvDict.values())
    minSv=min(svDict.values())
    maxSV=max(svDict.values())
    
    fvInterval=(maxFv-minFv)/noOfC
    svInterval=(maxSV-minSv)/noOfR
    fvInterList=[]
    svInterList=[]
    for i in range(int(noOfC)):
        fvInterList.append(minFv+(i*fvInterval))
    for j in range(int(noOfR)):
        svInterList.append(minSv+(j*svInterval))
        
   
    svList=[]
    fvList=[]
    for svi in range(len(svInterList)):
        svList.append([])
        for sk,sv in svDict.items(): 
            if svi!= (len(svInterList)-1):
                if svInterList[svi]<=sv<svInterList[svi+1]:
                    svList[svi].append(sk)                
            else:
                if sv >= svInterList[svi]:
                    svList[svi].append(sk)
    
    for fvi in range(len(fvInterList)):           
        fvList.append([])
        for fk,fv in fvDict.items(): 
            if fvi != (len(fvInterList)-1):                
                if fvInterList[fvi]<=fv<fvInterList[fvi+1]:
                    fvList[fvi].append(fk)    
            else:
                if fv >= fvInterList[fvi]:
                    fvList[fvi].append(fk)
            
    for i in range(len(svList)):
        bvList.append([])
        for j in range(len(fvList)):
            bvList[i].append([])
            for si in svList[i]:
                if si in fvList[j]:
                    bvList[i][j].append(si)
            for fi in fvList[j]:
                if (fi in svList[i]) and (not fi in bvList[i][j]):
                    bvList[i][j].append(fi)
    
    fvInterList.append(fvInterList[-1]+fvInterval)
    svInterList.append(svInterList[-1]+svInterval)
    return [bvList, fvInterList, svInterList]

if __name__=='__main__':
    bva=bvAnalysis({'r1':{'a': 1, 'b': 2}, 'r2':{'a': 2, 'b': 3}, 'r3':{'a': 3, 'b': 4}, 'r4':{'a': 4, 'b': 5}}, 'a', 3, 'b', 3)
    print bva
    